package com.gmail.dengtao.joe.group.channel;

import com.gmail.dengtao.joe.group.interceptor.InterceptorStack;
import com.gmail.dengtao.joe.group.member.Member;
import com.gmail.dengtao.joe.group.member.MembershipListener;
import com.gmail.dengtao.joe.group.transport.ChannelReceiver;
import com.gmail.dengtao.joe.group.transport.ChannelSender;

public interface Channel {

	/**
	 * Unique number sequence.
	 * @return
	 * @since 1.0
	 */
	public String getId();

	/**
     * Starts up the channel. This can be called multiple times for individual services to start
     * The svc parameter can be the logical or value of any constants
     */
    public void open();

    /**
     * Shuts down the channel. This can be called multiple times for individual services to shutdown
     * The svc parameter can be the logical or value of any constants
     */
    public void close();
	
    /**
     * Add a ne member in this channel.
     * @since 1.0
     */
    public void addMember(Member member);
    
	/**
	 * Get all current group members
     * @return all members or empty array, never null
	 * @since 1.0
	 */
	public Member[] getMembers();
	
	/**
     * Send a message to the destinations specified
     * @param destination Member[] - destination.length > 1
     * @param msg the message to send
     */
	public void send(Member[] destination, Object data);

	/**
     * Send a message to the destinations specified
     * @param destination Member[] - destination.length > 1
     * @param data the message to send
     */
	public void send(Member target, Object data);

	/**
	 * Broadcast message to all avaliable member.
	 * @param string
	 * @since 1.0
	 */
	public void broadcast(Object data);

	/**
	 * Set MembershipListener for this Receiver.
	 * @param membershipListener
	 * @since 1.0
	 */
	public void setMembershipListener(MembershipListener membershipListener);

	/**
	 * Set ChannelListener for this Receiver.
	 * @param channelListener
	 * @since 1.0
	 */
	public void setChannelListener(ChannelListener channelListener);
	
	/**
	 * Get InterceptorStack of this Receiver.
	 * @return
	 * @since 1.0
	 */
	public InterceptorStack getInterceptorStack();
	
	/**
	 * set unique id for this channel.
	 * @param id
	 * @since 1.0
	 */
	public void setId(String id);

	/**
	 * @return sender of this channel.
	 * @since 1.0
	 */
	public ChannelSender getChannelSender();

	/**
	 * @return receiver of this channel
	 * @since 1.0
	 */
	public ChannelReceiver getChannelReceiver();

	public Member getMember(String uuid);

	public void removeMember(Member member);

}
